package com.nzd.slsharing.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nzd.slsharing.pojo.Comment;
import com.nzd.slsharing.pojo.PostSection;
import com.nzd.slsharing.pojo.Suggestion;
import com.nzd.slsharing.pojo.User;
import com.nzd.slsharing.service.PostSectionService;
import com.nzd.slsharing.service.SuggestionService;
import com.nzd.slsharing.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.Date;

import static com.nzd.slsharing.util.ResultCodeEnum.ARGUMENT_VALID_ERROR;

@RestController
@RequestMapping("/api/postSection")
public class PostSectionController {
    @Resource
    private PostSectionService postSectionService;


    @PostMapping("/add")
    public Result addPostSection(@RequestBody PostSection postSection) {
        postSection.setCreateTime(new Date());
        return Result.ok(postSectionService.save(postSection));
    }

    @GetMapping("/getPostSection")
    public Result getPostSection() {

        return Result.ok(postSectionService.list());
    }

    //查询用户列表
    @GetMapping("/list")
    public Result list() {
        return Result.ok(postSectionService.list());
    }

    //查询用户列表 带分页
    @GetMapping("/pageList")
    public Result pageList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(required = false, defaultValue = "3") Integer pageSize) {
        // 设置分页参数
        Page<PostSection> page = new Page<>(pageNum, pageSize);
        return Result.ok(postSectionService.page(page));
    }

    //修改
    @PutMapping("/update")
    public Result update(@RequestBody PostSection postSection) {
        postSection.setUpdateTime(new Date());
        return Result.ok(postSectionService.updateById(postSection));
    }


    //删除
    @DeleteMapping("/{id}")
    public Result del(@PathVariable Long id) {
        return Result.ok(postSectionService.removeById(id));
    }
}
